{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-01-08T03:00:40.714974Z",
     "start_time": "2025-01-08T03:00:40.041644Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "#duplicated() 返回布尔型 Series 表示每行是否为重复行\n",
    "df_obj = pd.DataFrame({'data1' : ['a'] * 4 + ['b'] * 4,'data2' : np.random.randint(0, 4, 8)})\n",
    "print(df_obj)\n",
    "print(df_obj.duplicated())"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  data1  data2\n",
      "0     a      1\n",
      "1     a      0\n",
      "2     a      1\n",
      "3     a      3\n",
      "4     b      0\n",
      "5     b      1\n",
      "6     b      0\n",
      "7     b      0\n",
      "0    False\n",
      "1    False\n",
      "2     True\n",
      "3    False\n",
      "4    False\n",
      "5    False\n",
      "6     True\n",
      "7     True\n",
      "dtype: bool\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-08T03:00:54.989266Z",
     "start_time": "2025-01-08T03:00:54.981414Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#drop_duplicates() 过滤重复行\n",
    "print(df_obj.drop_duplicates())\n",
    "print(df_obj.drop_duplicates('data2'))"
   ],
   "id": "641c8ab96313d4a8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  data1  data2\n",
      "0     a      1\n",
      "1     a      0\n",
      "3     a      3\n",
      "4     b      0\n",
      "5     b      1\n",
      "  data1  data2\n",
      "0     a      1\n",
      "1     a      0\n",
      "3     a      3\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-08T03:01:03.083014Z",
     "start_time": "2025-01-08T03:01:03.076783Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#根据 map 传入的函数对每行或每列进行转换\n",
    "ser_obj = pd.Series(np.random.randint(0,10,10))\n",
    "print(ser_obj)\n",
    "print(ser_obj.map(lambda x : x ** 2))"
   ],
   "id": "da99c80b87760282",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    2\n",
      "1    1\n",
      "2    8\n",
      "3    7\n",
      "4    8\n",
      "5    1\n",
      "6    8\n",
      "7    7\n",
      "8    6\n",
      "9    9\n",
      "dtype: int32\n",
      "0     4\n",
      "1     1\n",
      "2    64\n",
      "3    49\n",
      "4    64\n",
      "5     1\n",
      "6    64\n",
      "7    49\n",
      "8    36\n",
      "9    81\n",
      "dtype: int64\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-08T03:01:48.544368Z",
     "start_time": "2025-01-08T03:01:48.536194Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#replace 根据值的内容进行替换\n",
    "\n",
    "# 单个值替换单个值\n",
    "print(ser_obj.replace(1, -100))\n",
    "# 多个值替换一个值\n",
    "print(ser_obj.replace([6, 8], -100))\n",
    "# 多个值替换多个值\n",
    "print(ser_obj.replace([4, 7], [-100, -200]))"
   ],
   "id": "21910c453081188a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0      2\n",
      "1   -100\n",
      "2      8\n",
      "3      7\n",
      "4      8\n",
      "5   -100\n",
      "6      8\n",
      "7      7\n",
      "8      6\n",
      "9      9\n",
      "dtype: int32\n",
      "0      2\n",
      "1      1\n",
      "2   -100\n",
      "3      7\n",
      "4   -100\n",
      "5      1\n",
      "6   -100\n",
      "7      7\n",
      "8   -100\n",
      "9      9\n",
      "dtype: int32\n",
      "0      2\n",
      "1      1\n",
      "2      8\n",
      "3   -200\n",
      "4      8\n",
      "5      1\n",
      "6      8\n",
      "7   -200\n",
      "8      6\n",
      "9      9\n",
      "dtype: int32\n"
     ]
    }
   ],
   "execution_count": 4
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
